package com.ruoyi.personnel.oa.schedule.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.personnel.oa.schedule.domain.MySchedule;
import com.ruoyi.personnel.oa.schedule.domain.ScheduleCond;
import com.ruoyi.personnel.oa.schedule.service.IMyScheduleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 视图层
 * 我的日程
 */
@RestController
@RequestMapping("/oa/mySchedule")
@Api(value = "我的日程模块", tags = "我的日程接口")
public class MyScheduleController extends BaseController {
    @Autowired
    private IMyScheduleService myScheduleService;

    /**
     * 根据搜索条件所有我的日程记录
     *
     * @param cond 搜索条件
     * @return
     */
    @ApiOperation(value = "获取我的日程记录列表", notes = "查询所有我的日程记录信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ScheduleCond cond) {
        startPage();
        List<MySchedule> schedules = myScheduleService.selectMyScheduleList(cond);
        return getDataTable(schedules);
    }

    /**
     * 导出我的日程记录
     *
     * @param cond
     * @return
     */
    @PostMapping("/export")
    @ApiOperation("导出我的日程")
    public AjaxResult export(@RequestBody ScheduleCond cond) {
        List<MySchedule> schedules = myScheduleService.selectMyScheduleList(cond);
        ExcelUtil<MySchedule> util = new ExcelUtil<>(MySchedule.class);
        return util.exportExcel(schedules, "我的日程记录");
    }

    /**
     * 新增我的日程记录
     *
     * @param schedule
     * @return
     */
    @ApiOperation(value = "新增我的日程记录", notes = "新增我的日程记录")
    @ApiImplicitParam(name = "schedule", value = "新增我的日程记录", dataType = "MySchedule")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody MySchedule schedule) {
        return toAjax(myScheduleService.insertMySchedule(schedule));
    }

    /**
     * 修改我的日程记录
     *
     * @param schedule
     * @return
     */
    @ApiOperation(value = "修改我的日程记录", notes = "修改我的日程记录")
    @ApiImplicitParam(name = "schedule", value = "修改我的日程记录", dataType = "MySchedule")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody MySchedule schedule) {
        return toAjax(myScheduleService.updateMySchedule(schedule));
    }

    /**
     * 删除我的日程记录
     * 仅修改删除标志
     *
     * @param schedule
     * @return
     */
    @ApiOperation(value = "删除我的日程记录", notes = "删除我的日程记录,仅删除标志位")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody MySchedule schedule) {
        return toAjax(myScheduleService.updateMyScheduleDeleteFlag(schedule));
    }
}
